I have a basic QML/C++ Qt app I am able to compile to WebAssembly using Emscripen.
I am trying to use pybind11 on the C++ side so I can embed Python.
It works as expected when I build and execute on my system.
#if defined(_DEBUG)
#undef _DEBUG
#include
#define _DEBUG
#else
#include
#endif
#include
#include
#include
#include
#include
using namespace std;
void say_something ()
{
printf ("Say Something nicely\n");
}
static int COUNTER = 0;
void set_counter (int count)
{
COUNTER = count;
}
struct MyData
{
float x;
};
struct MyDataPython
{
float x;
float y;
MyDataPython () : x(0), y(0) {}
MyDataPython (float x, float y) : x(x), y(y) {}
};
PYBIND11_EMBEDDED_MODULE (embeddedmodule, module)
{
module.doc () = "Embedded Module";
module.def ("say_something", &say_something);
module.def ("set_counter", &set_counter);
pybind11::class_(module, "MyData")
.def_readwrite ("x", &MyData::x);
}
int main(int argc, char *argv[])
{
// TESTING pybind11 stuff here /////////////////////////////////////////////////////////////////////
pybind11::scoped_interpreter guard{};
//Python executed
pybind11::exec ("print('hello world')");
pybind11::exec ("from test_mod import Test");
pybind11::exec ("test = Test()");
pybind11::exec ("import embeddedmodule\nembeddedmodule.say_something()");
cout |